package mc

import (
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	ReadWriteEventNew          = "study.ReadWriteNew"
	ReadWriteEventBeforeCreate = "study.ReadWriteBeforeCreate"
	ReadWriteEventBeforeUpdate = "study.ReadWriteBeforeUpdate"
	ReadWriteEventBeforeSave   = "study.ReadWriteBeforeCreate study.ReadWriteBeforeUpdate"
	ReadWriteEventAfterCreate  = "study.ReadWriteAfterCreate"
	ReadWriteEventAfterUpdate  = "study.ReadWriteAfterUpdate"
	ReadWriteEventAfterSave    = "study.ReadWriteAfterCreate study.ReadWriteAfterUpdate"
	ReadWriteEventDelete       = "study.ReadWriteDelete"

	ReadWriteAccessControlEvent = "study.ReadWriteAccessControl"
)

func GetReadWriteConfig() *mgo.DocConfig {
	return ReadWrite_Config
}

var ReadWrite_Config *mgo.DocConfig

func init() {
	ReadWrite_Config = NewReadWriteConfig()
}

func NewReadWriteConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "study.ReadWrite",
		Fields: []string{
			"read", "write", "sense", "note", "subject", "grade", "knowledge", "mp3",
		},
		RelationFields: []string{
			"subject", "grade", "knowledge",
		},
		RelationConfigs: map[string]*mgo.DocRelation{

			"subject": {
				Config:     GetSubjectConfig,
				DocName:    "Subject",
				JoinType:   "O",
				KeyInside:  "subjectId",
				KeyOutSide: "id",
			},

			"grade": {
				Config:     GetGradeConfig,
				DocName:    "Grade",
				JoinType:   "O",
				KeyInside:  "gradeId",
				KeyOutSide: "id",
			},

			"knowledge": {
				Config:     GetKnowledgeConfig,
				DocName:    "Knowledge",
				JoinType:   "O",
				KeyInside:  "knowledgeId",
				KeyOutSide: "id",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
